function query_imdb_rating() {
    var link = $('a[href^="http://www.imdb.com"]');

    link.append("<img id='loading' src='" + chrome.extension.getURL('/assets/img/loading.gif') + "' style='width: 24px'>");

    $.ajax({
    url: link.attr('href'),
    type: 'GET',
    dataType: 'html',
    complete: function (xhr, status) {
        if (status == 301) {
            console.log("redirect");

            var fn = arguments.callee;
            var _this = this;
            setTimeout(function(){fn.call(_this, xhr, status);}, 200);
        }
        else {
            $('#loading').hide();
        }
    },
    success: function (html) {
        var doc = $(html);
        var rating = parseFloat(doc.find('div.star-box-giga-star').text());

        link.append("<div style='background=url(" + chrome.extension.getURL('/assets/img/rating.png') + ") no-repeat;'>" + rating + "</div>");
    }});
}

read_option('imdb_rating', function (k, v) {
    if (v) {
        query_imdb_rating();
    }
});